home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / yacas_alg / yacas_morphos / share / yacas / functional.rep / code.ys < prev   
Encoding:
Text File  |  2002-03-13  |  1.1 KB  |  39 lines

  1.  
  2. /* Operators for functional programming.
  3.  * Examples:
  4.  *  a:b:c:{}       ->  {a,b,c}
  5.  *  "Sin" @ a      ->   Sin(a)
  6.  *  "Sin" @ {a,b}  ->   Sin(a,b)
  7.  *  "Sin" /@ {a,b} ->   {Sin(a),Sin(b)}
  8.  *  1 .. 4         ->   {1,2,3,4}
  9.  */
  10.  
  11.  
  12. RuleBase(":",{head,tail});
  13. Rule(":",2,1,IsList(tail)  ) Concat({head},tail);
  14. Rule(":",2,1,IsString(tail)) ConcatStrings(head,tail);
  15. UnFence(":",2);
  16.  
  17.  
  18. RuleBase("@",{func,arg});
  19. Rule("@",2,1,IsList(arg)) Apply(func,arg);
  20. Rule("@",2,2,True       ) Apply(func,{arg});
  21.  
  22. Function("/@",{func,lst}) Apply("MapSingle",{func,lst});
  23.  
  24. Function("..",{from,to}) Table(i,i,from,to,1);
  25.  
  26.  
  27. /* NFunction("new'func", "old'func" {arg'list}) will define a wrapper function
  28. around  "old'func", called "new'func", which will return "old'func(arg'list)"
  29. only when all arguments are numbers and will return unevaluated
  30. "new'func(arg'list)" otherwise. */
  31.  
  32. NFunction(new'name_IsString, old'name_IsString, arg'list_IsList) <-- [
  33.     MacroRuleBase(new'name, arg'list);
  34.     MacroRule(new'name, Length(arg'list), 0,    // check whether all args are numeric
  35.         UnList({IsNumericList, arg'list})
  36.     )
  37.         UnList({Atom("@"), old'name, arg'list}); // cannot use '@' b/c get a syntax error
  38. ];
  39.